package demoMod.invincibleOne.patches;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePostfixPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.cutscenes.Cutscene;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.map.MapRoomNode;
import com.megacrit.cardcrawl.monsters.MonsterGroup;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import com.megacrit.cardcrawl.rooms.TrueVictoryRoom;
import com.megacrit.cardcrawl.screens.DeathScreen;
import com.megacrit.cardcrawl.screens.GameOverScreen;
import com.megacrit.cardcrawl.screens.VictoryScreen;
import com.megacrit.cardcrawl.screens.options.ConfirmPopup;
import com.megacrit.cardcrawl.vfx.AbstractGameEffect;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.characters.InvincibleOne;
import demoMod.invincibleOne.effects.EndCGEffect;
import demoMod.invincibleOne.enums.AbstractPlayerEnum;
import demoMod.invincibleOne.relics.SecondWindRelic;

public class DeathScreenPatch {

    @SpirePatch(
            clz = DeathScreen.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static SpireReturn<Void> Prefix(GameOverScreen screen, MonsterGroup group) {
            if (AbstractDungeon.player instanceof InvincibleOne && AbstractPlayerPatch.PatchDamage.deadByDamage) {
                if (!AbstractDungeon.player.hasRelic(SecondWindRelic.ID) || AbstractDungeon.player.hasRelic(SecondWindRelic.ID) &&
                        AbstractDungeon.player.getRelic(SecondWindRelic.ID).counter <= 0) {
                    if (InvincibleOneMod.provoked[CardCrawlGame.saveSlot] && !InvincibleOneMod.reskinUnlocked[CardCrawlGame.saveSlot]) {
                        InvincibleOneMod.provoked[CardCrawlGame.saveSlot] = false;
                        InvincibleOneMod.save.setBool("provoked" + CardCrawlGame.saveSlot, true);
                        InvincibleOneMod.reskinUnlocked[CardCrawlGame.saveSlot] = true;
                        InvincibleOneMod.save.setBool("reskinUnlocked" + CardCrawlGame.saveSlot, true);
                        try {
                            InvincibleOneMod.save.save();
                        } catch (Exception e) {}
                    }

                    AbstractDungeon.screen = AbstractDungeon.CurrentScreen.VICTORY;
                    CardCrawlGame.music.silenceTempBgmInstantly();
                    CardCrawlGame.music.silenceBGMInstantly();
                    CardCrawlGame.music.playTempBgmInstantly("STS_EndingStinger_v1.ogg", false);
                    AbstractDungeon.victoryScreen = new VictoryScreen(group);
                    AbstractDungeon.player.stance.stopIdleSfx();
                }
                AbstractPlayerPatch.PatchDamage.deadByDamage = false;
                return SpireReturn.Return(null);
            }
            return SpireReturn.Continue();
        }
    }
}
